package com.zxc.demo.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zxc.demo.model.HuoJia;
import com.zxc.demo.service.HuoJiaService;
import com.zxc.demo.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

@Controller
@RequestMapping("/decoration")
public class ShopDecorationController {
    @Resource
    private HuoJiaService huoJiaService;


    @RequestMapping(value = "/updateshelfbya")
    @ResponseBody
    public R updateshelfbya (@RequestBody List<HuoJia> shelfs){
        QueryWrapper<HuoJia> swrapper = new QueryWrapper<>();
        huoJiaService.remove(swrapper);
        //新增关联数据
        huoJiaService.saveOrUpdateBatch(shelfs);
        return R.success(true);
    }
    /**
     * 获取店铺类目
     * @return
     */
    @RequestMapping(value = "/getShopShelf")
    @ResponseBody
    public R getShopShelf (HttpServletRequest request){
        List<HuoJia> list = huoJiaService.list(new LambdaQueryWrapper<HuoJia>()
                .eq(HuoJia::getIsDelete, 0));
        return R.success(list);
    }

}
